package edu.gatech.asthma.activity;

import java.util.ArrayList;

import edu.gatech.asthma.R;
import edu.gatech.asthma.database.DBAdapter;
import edu.gatech.asthma.ui_support.HelpMenuHelper;
import android.os.Bundle;
import android.app.Activity;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.TextView;

/**
 * Activity that displays a single symptom record entry to the user
 */
public class ShowSymptomRecordDetailActivity extends Activity {
	int identifier = -1;
	int recordID = -1;
	boolean younger;
	DBAdapter database;
	String[] symptomList;
	ArrayList<String> result;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_show_symptom_record_detail);
		
		getActionBar().setTitle("Record Details");
		
		Bundle extras = getIntent().getExtras();
		if (extras != null) {
			identifier = extras.getInt("ID");
			recordID = extras.getInt("RecordID");
			younger = extras.getBoolean("Age");
		}
		database = new DBAdapter(this);
		database.open();
		
		TextView name = (TextView)findViewById(R.id.txtRecordName);
		TextView date = (TextView)findViewById(R.id.txtRecordDate);
		
		name.setText(database.getProfile(identifier).getName());
		date.setText(database.getSymptomRecordByID(recordID).getDate());
		
		ListView listview = (ListView)findViewById(R.id.RecordDetailList);
		String rawSymptomData = database.getSymptomRecordByID(recordID).getSymptoms();
		
		if(younger) {
			symptomList = getResources().getStringArray(R.array.symptoms_younger);
		} else {
			symptomList = getResources().getStringArray(R.array.symptoms_older);
		}
		
		result = new ArrayList<String>();
		for(int a = 0; a < symptomList.length; a++){
			if(rawSymptomData.charAt(a) == 'T') {
				result.add(symptomList[a]);
			}
		}
		
		ListAdapter adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, result);
		listview.setAdapter(adapter);
	}
	
	/**
	 * User clicked the help button on this screen
	 * @param v ImageView clicked
	 */
	public void helpButtonClicked(View v) {
		HelpMenuHelper.displayHelpMessage(this);
	}
}
